package com.seven.dao;

import java.util.List;

import com.seven.entity.Problem;

//问题dao
public class ProblemDao extends BaseDao{

	/**
	 * 添加问题
	 */
	public int addProblem(Problem problem) {
		String sql = "insert into problem(problem_title, problem_content, problem_addcontent, problem_time, problem_address, problem_picture, problem_bickunm, problem_picture2, problem_isauditor, problem_ispass, users_id, worker_id) values(?,?,?,?,?,?,?,?,?,?,?,?)";
		Object[] ob = {problem.getProblem_title(),problem.getProblem_content(),problem.getProblem_addcontent(),problem.getProblem_time(),problem.getProblem_address(),problem.getProblem_picture(),problem.getProblem_bickunm(),problem.getProblem_picture2(),problem.getProblem_isauditor(),problem.getProblem_ispass(),problem.getUsers_id(),problem.getWorker_id()};
		return super.update(sql, ob);
		
	}
	
	/**
	 * 删除问题
	 */
	public int deleteProblem(Problem problem) {
		String sql = "delete from problem where problem_id=?";
		int ob = problem.getProblem_id();
		return super.update(sql, ob);
	}
	
	/**
	 * 更新问题
	 */
	public int updatePromblem(Problem problem) {
		String sql = "update problem set problem_title=?, problem_content=?, problem_addcontent=?, problem_time=?, problem_address=?, problem_picture=?, problem_bickunm=?, problem_picture2=?, problem_isauditor=?, problem_ispass=? where problem_id =?";
		Object[] ob = {problem.getProblem_title(),problem.getProblem_content(),problem.getProblem_addcontent(),problem.getProblem_time(),problem.getProblem_address(),problem.getProblem_picture(),problem.getProblem_bickunm(),problem.getProblem_picture2(),problem.getProblem_isauditor(),problem.getProblem_ispass() ,problem.getProblem_id()};
		return super.update(sql, ob);
		
	}
	
	/**
	 * 指派员工并修改处理状态为处理中
	 */
	public int setWorkerid(Problem problem) {
		String sql = "update problem set problem_ispass = ? ,worker_id = ? where problem_id = ?";
		Object[] ob = {problem.getProblem_ispass(),problem.getWorker_id(), problem.getProblem_id()};
		return super.update(sql, ob);
	}
	
	/**
	 * 查询所有问题
	 */
	public List<Problem> selectAllProblem() {
		String sql = "select * from problem";
		return super.query2(sql, Problem.class);
		
	}
	
	/**
	 * 通过id查询问题
	 */
	public List<Problem> selectByProblem_id(Problem problem) {
		
		String sql = "select * from problem where problem_id=?";
		int ob = problem.getProblem_id();
		return super.query2(sql, Problem.class, ob);
	
	}
	
	/**
	 * 通过用户id查询问题
	 */
	public List<Problem> selectByUsers_id(Problem problem) {
		String sql = "select * from problem where users_id=?";
		int ob = problem.getUsers_id();
		return super.query2(sql, Problem.class, ob);
		
	}
	
	/**
	 * 通过员工id查询问题
	 */
	public List<Problem> selectByWorker_id(Problem problem) {
		String sql = "select * from problem where worker_id=?";
		int ob = problem.getWorker_id();
		return super.query2(sql, Problem.class, ob);
		
	}
	
	/**
	 * 查询出所有未的问题
	 */
	public List<Problem> selectByproblem_isauditor0() {
		String sql = "select * from problem where problem_isauditor=0";
		return super.query2(sql, Problem.class);
		
	}
	
	/**
	 * 查询出所有已审核的问题
	 */
	public List<Problem> selectByproblem_isauditor_1() {
		String sql = "select * from problem where problem_isauditor=-1";
		return super.query2(sql, Problem.class);
		
	}
	
	/**
	 * 查询出所有已审核的问题
	 */
	public List<Problem> selectByproblem_isauditor1() {
		String sql = "select * from problem where problem_isauditor=1";
		return super.query2(sql, Problem.class);
		
	}
	
	/**
	 * 查询出所有未处理的问题
	 */
	public List<Problem> selectByproblem_ispass_1() {
		String sql = "select * from problem where problem_ispass=-1 and problem_isauditor=1";
		return super.query2(sql, Problem.class);
		
	}
	
	/**
	 * 查询出所有处理中的问题
	 */
	public List<Problem> selectByproblem_ispass0() {
		String sql = "select * from problem where problem_ispass=0";
		return super.query2(sql, Problem.class);
		
	}
	
	/**
	 * 查询出所有已处理的问题
	 */
	public List<Problem> selectByproblem_ispass1() {
		String sql = "select * from problem where problem_ispass=1";
		return super.query2(sql, Problem.class);
		
	}
	
	
}
